package com.ruoyi.slope.inspection.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.slope.dataFile.domain.SlopeDataFile;
import com.ruoyi.slope.dataFile.service.ISlopeDataFileService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.slope.inspection.domain.SlopeInspectionWeather;
import com.ruoyi.slope.inspection.service.ISlopeInspectionWeatherService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 气象条件观察巡检Controller
 * 
 * @author ruoyi
 * @date 2025-09-05
 */
@RestController
@RequestMapping("/slope/weather")
public class SlopeInspectionWeatherController extends BaseController
{
    @Autowired
    private ISlopeDataFileService slopeDataFileService;
    @Autowired
    private ISlopeInspectionWeatherService slopeInspectionWeatherService;

    /**
     * 查询气象条件观察巡检列表
     */
    @PreAuthorize("@ss.hasPermi('slope:weather:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlopeInspectionWeather slopeInspectionWeather)
    {
        startPage();
        List<SlopeInspectionWeather> list = slopeInspectionWeatherService.selectSlopeInspectionWeatherList(slopeInspectionWeather);
        return getDataTable(list);
    }

    /**
     * 导出气象条件观察巡检列表
     */
    @PreAuthorize("@ss.hasPermi('slope:weather:export')")
    @Log(title = "气象条件观察巡检", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlopeInspectionWeather slopeInspectionWeather)
    {
        List<SlopeInspectionWeather> list = slopeInspectionWeatherService.selectSlopeInspectionWeatherList(slopeInspectionWeather);
        ExcelUtil<SlopeInspectionWeather> util = new ExcelUtil<SlopeInspectionWeather>(SlopeInspectionWeather.class);
        String path = util.exportExcel(response, list, "气象条件观察巡检数据");
        SlopeDataFile slopeDataFile = new SlopeDataFile();
        slopeDataFile.setFileName(path);
        slopeDataFileService.insertSlopeDataFile(slopeDataFile);
    }

    /**
     * 获取气象条件观察巡检详细信息
     */
    @PreAuthorize("@ss.hasPermi('slope:weather:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(slopeInspectionWeatherService.selectSlopeInspectionWeatherById(id));
    }

    /**
     * 新增气象条件观察巡检
     */
    @PreAuthorize("@ss.hasPermi('slope:weather:add')")
    @Log(title = "气象条件观察巡检", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlopeInspectionWeather slopeInspectionWeather)
    {
        return toAjax(slopeInspectionWeatherService.insertSlopeInspectionWeather(slopeInspectionWeather));
    }

    /**
     * 修改气象条件观察巡检
     */
    @PreAuthorize("@ss.hasPermi('slope:weather:edit')")
    @Log(title = "气象条件观察巡检", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlopeInspectionWeather slopeInspectionWeather)
    {
        return toAjax(slopeInspectionWeatherService.updateSlopeInspectionWeather(slopeInspectionWeather));
    }

    /**
     * 删除气象条件观察巡检
     */
    @PreAuthorize("@ss.hasPermi('slope:weather:remove')")
    @Log(title = "气象条件观察巡检", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(slopeInspectionWeatherService.deleteSlopeInspectionWeatherByIds(ids));
    }
}
